/**
 * 
 */
function setupProvince(self, city, county){
	$.getJSON(URL_PREFIX + '/area/areasJson.do', function (data){
		var areas = eval(data);
		var optinoStr = "";
		for(i=0; i< areas.length; i++){// 
			selectedStr = "";
			if (areas[i].code == self){
				selectedStr = "selected='selected' ";
			}
			optinoStr += "<option " + selectedStr + "value='" + areas[i].code + "'>" + areas[i].name + "</option>";
		}
		$("#province").html(optinoStr);
		if (self == null || self == ""){
			self = areas[0].code;
		}
		setupCity(self, city, county);
	});
}

	
function setupCity (parentCode, self, subArea){
	var ajaxUrl = URL_PREFIX  + '/area/areasJson.do?parentCode=' + parentCode;
	$.getJSON(ajaxUrl, function (data){
		var areas = eval(data);
		var optinoStr = "<option value='0'>-- 请选择  --</option>";
		for(i=0; i< areas.length; i++){// 
			selectedStr = "";
			if (areas[i].code == self){
				selectedStr = "selected='selected' ";
			}
			optinoStr += "<option " + selectedStr + "value='" + areas[i].code + "'>" + areas[i].name + "</option>";
		}
		$("#city").html(optinoStr);
		if (areas.length > 0 && (self == null || self == "")){
			self = areas[0].code;
		}
		setupCounty(self, subArea);
	});
}

function setupCounty (parentCode, self){
	var ajaxUrl = URL_PREFIX + '/area/areasJson.do?parentCode=' + parentCode
	$.getJSON(ajaxUrl, function (data){
		var areas = eval(data);
		var optinoStr = "<option value='0'>-- 请选择  --</option>";
		for(i=0; i< areas.length; i++){// 
			selectedStr = "";
			if (areas[i].code == self){
				selectedStr = "selected='selected' ";
			}
			optinoStr += "<option " + selectedStr+ "value='" + areas[i].code + "'>" + areas[i].name + "</option>";
		}
		$("#county").html(optinoStr);
	});
}

function setupArea(code){
	var county, city, province;
	if (code.substring(4, 6) != "00"){// 区县级
		county = code;
		city = code.substring(0, 4) + "00";
		province = code.substring(0, 2) + "0000";
	} else if (code.substring(2, 4) != "00"){ //市级
		city = code;
		province = code.substring(0, 2) + "0000";
	} else {//省级
		province = code;
	}
	setupProvince(province,city,county);
	/**
	if (province != null){
	}
	if (city != null){
		_city = "#" + city;
		alert(_city);
		$(_city).attr("selected","selected");
		setCounty(city);
	}
	if (county != null){
		_county = "#" + county; 
		$(_county).attr("selected","selected");
	}
	*/
}
	
